package com.sq.universe.base.conf;


import com.github.pagehelper.QueryInterceptor;
import com.sq.universe.base.interceptor.DataPermissionInterceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.List;

@Configuration
public class DataPermissionConf {

    @Autowired
    private List<SqlSessionFactory> sqlSessionFactoryList;

    @PostConstruct
    public void addMyInterceptor() {
        DataPermissionInterceptor dataPermissionInterceptor = new DataPermissionInterceptor();
        QueryInterceptor queryInterceptor = new QueryInterceptor();
        for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
            sqlSessionFactory.getConfiguration().addInterceptor(queryInterceptor);
            sqlSessionFactory.getConfiguration().addInterceptor(dataPermissionInterceptor);
        }
        
    }
}
